package com.pingsky.apm.agent.core.trace;


import com.pingsky.apm.agent.core.util.StringUtil;

import java.util.UUID;
import java.util.concurrent.atomic.AtomicLong;

public final class GlobalIdGenerator {

    private final static String PROCESS_ID = UUID.randomUUID().toString().replaceAll("-", "");

    private final static AtomicLong SEQUENCE = new AtomicLong(1L);

    private GlobalIdGenerator() {
    }

    public static String generate() {
        return StringUtil.join(
                '.',
                PROCESS_ID,
                String.valueOf(Thread.currentThread().getId()),
                String.valueOf(SEQUENCE.getAndIncrement())
        );
    }
}
